<{extends file="$elementPath/layout/index.html"}>
<{block name='body'}>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
                 style="padding: 20px ">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">角色分组</label>
                    <div class="layui-input-block">
                        <select name="parent_id">
                            <option value="0" selected>顶级权限分组</option>
                            <{foreach from=$groupList item=item}>
                            <option value="<{$item->gid}>"
                            <{if isset($data) and $item->gid eq $data->parent_id}>selected<{/if}>><{$item->gname}>
                            </option>
                            <{/foreach}>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="gname" lay-verify="required" placeholder="角色名称" <{if
                        isset($data)}>value="<{$data->gname}>"<{/if}> autocomplete="off"
                        class="layui-input">
                    </div>
                </div>
                <div class="layui-card">
                    <div class="layui-card-header">选择权限</div>
                    <div class="layui-card-body">
                        <div class="layui-tab">
                            <ul class="layui-tab-title">
                                <{foreach $allrights as $item}>
                                <li class="<{if $item@first }>layui-this<{/if}>"> <{$item.name}></li>
                                <{/foreach}>
                            </ul>
                            <div class="layui-tab-content">
                                <{foreach $allrights as $item}>
                                <div class="layui-tab-item <{if $item@first }>layui-show<{/if}>">
                                    <{if $item.children}>
                                        <{foreach $item.children as $child}>
                                            <{if $child.children}>
                                                <div class="layui-form-item" pane="">
                                                    <label class="layui-form-label"><{$child.name}></label>
                                                    <div class="layui-input-block">
                                                        <{foreach $child.children as $child2}>
                                                        <input type="checkbox" name="rights[]"
                                                        <{if isset($groupRight) and
                                                        in_array($child2.id,$groupRight)}>checked="checked"<{/if}>
                                                        value="<{$child2.id}>"
                                                        lay-skin="primary" title="<{$child2.name}>" />
                                                        <{/foreach}>
                                                    </div>
                                                </div>
                                            <{else}>
                                                <div class="layui-form-item" pane="">
                                                    <label class="layui-form-label"><{$child.name}></label>
                                                    <div class="layui-input-block">
                                                        <input type="checkbox" name="rights[]"
                                                        <{if isset($groupRight) and in_array($child.id,$groupRight)}>checked="checked"<{/if}>
                                                        value="<{$child.id}>" lay-skin="primary" title="<{$child.name}>" />
                                                    </div>
                                                </div>
                                            <{/if}>
                                        <{/foreach}>
                                    <{else}>
                                    <div class="layui-form-item" pane="">
                                        <label class="layui-form-label"><{$item.name}></label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="rights[]"
                                            <{if isset($groupRight) and in_array($item.id,$groupRight)}>checked="checked"<{/if}>
                                            value="<{$item.id}>" lay-skin="primary" title="<{$item.name}>" />
                                        </div>
                                    </div>
                                    <{/if}>
                                </div>
                                <{/foreach}>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="role-form-submit" id="role-form-submit"
                           value="确认添加">
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form;

        //监听提交
        form.on('submit(role-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/gid/<{if isset($data)}><{$data->gid}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    parent.layui.table.reload('role-table-page'); //重载表格
                    parent.layer.close(index); //再执行关闭
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>
<{/block}>